package com.atguigu.hbase.mr.fruit.hdfstohbase;

import com.atguigu.constant.CommonConstantValue;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;

import java.io.IOException;

/**
 * @ClassName FruitDriver
 * @DeScription FruitDriver
 * @Author 剧情再美终是戏
 * @Date 2019/12/9 10:04
 * @Version 1.0
 **/
public class FruitDriver {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        //设置输入路径
        Path inputPath = new Path(CommonConstantValue.HDFS_CONNECT_ADRESS + "/datas/dept");

        // 获取conf
        Configuration conf = HBaseConfiguration.create();

        // 创建job
        Job job = Job.getInstance(conf);
        job.setJobName("job1");

        // 设置mapper
        job.setMapperClass(FruitMapper.class);
        FileInputFormat.setInputPaths(job, inputPath);

        // 设置reducer
        TableMapReduceUtil.initTableReducerJob("dept", FruitReducer.class, job);

        // 设置输出格式
        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(Put.class);

        // 提交job
        job.waitForCompletion(true);
    }
}
